<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>attempt</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const attempt = (fn, ...args) => {
            try {
                return fn(...args);
            } catch (e) {
                return e instanceof Error ? e : new Error(e);
            }
        };
        let elements = attempt(selector => document.querySelectorAll(selector), '>_>');
        if (elements instanceof Error) elements = [];
        console.log(elements);
    </script>
</body>

</html>